<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <form action="" name="f1" onSubmit="validate()">
        姓名：<input type="text" id="username">
        <br> 性别：
        <select name="opt_name" id="opt">
            <option value="0">请选择性别</option>
            <option value="1">男</option>
            <option value="2">女</option>
        </select>
        <br>
        <input type="submit" name="submit" value="submit">
        <input type="reset" name="reset" value="reset">
    </form>
</body>

<script>
    document.f1.username.focus();

    function validate() {

        alert(document.f1.username.value);
        alert(document.getElementById("opt").value);
        // alert(document.f1.opt.value);

    }
</script>

</html>